﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:Peter.Common.Controls;assembly=Peter.Common">

   <ControlTemplate x:Key="TextBoxControlTemplate"
                    TargetType="TextBoxBase">
      <Grid>
         <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="FocusStates">
               <VisualState x:Name="Focused">
                  <Storyboard>
                     <DoubleAnimation BeginTime="00:00:00.000"
                                      Duration="00:00:00.300"
                                      From="0"
                                      To="1"
                                      Storyboard.TargetProperty="Opacity"
                                      Storyboard.TargetName="PART_TextBoxGlowBorder" />
                     <ColorAnimation Storyboard.TargetName="PART_TextBoxOverlayBorder"
                                     Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"
                                     To="{DynamicResource TextBoxHighlightColor}"
                                     Duration="0:0:0.25" />
                  </Storyboard>
               </VisualState>
               <VisualState x:Name="Unfocused">
                  <Storyboard>
                     <DoubleAnimation BeginTime="00:00:00.000"
                                      Duration="00:00:00.700"
                                      From="1"
                                      To="0"
                                      Storyboard.TargetProperty="Opacity"
                                      Storyboard.TargetName="PART_TextBoxGlowBorder" />
                     <ColorAnimation Storyboard.TargetName="PART_TextBoxOverlayBorder"
                                     Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"
                                     To="Transparent"
                                     Duration="0:0:0.25" />
                  </Storyboard>
               </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="CommonStates">
               <VisualState x:Name="Normal">
                  <Storyboard>
                     <ColorAnimation Storyboard.TargetName="PART_TextBoxBorder"
                                     Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"
                                     To="{DynamicResource MainBorderColor}"
                                     Duration="0:0:0.25" />
                  </Storyboard>
               </VisualState>
               <VisualState x:Name="MouseOver">
                  <Storyboard>
                     <ColorAnimation Storyboard.TargetName="PART_TextBoxBorder"
                                     Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"
                                     To="{DynamicResource TextBoxHighlightColor}"
                                     Duration="0:0:0.25" />
                  </Storyboard>
               </VisualState>
               <VisualState x:Name="Disabled">
                  <Storyboard>
                     <ColorAnimation Storyboard.TargetName="PART_ContentBorder"
                                     Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
                                     To="{DynamicResource DisabledBackgroundColor}"
                                     Duration="0:0:0.25" />
                  </Storyboard>
               </VisualState>
               <VisualState x:Name="ReadOnly">
                  <Storyboard>
                     <ColorAnimation Storyboard.TargetName="PART_ContentBorder"
                                     Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
                                     To="{DynamicResource SecondaryColor}"
                                     Duration="0:0:0.25" />
                  </Storyboard>
               </VisualState>
            </VisualStateGroup>
         </VisualStateManager.VisualStateGroups>
         <Border Padding="4"
                 x:Name="PART_ContentBorder"
                 Background="{DynamicResource BackgroundBrush}">
            <ScrollViewer x:Name="PART_ContentHost" />
         </Border>
         <Border x:Name="PART_TextBoxBorder"
                 BorderThickness="{TemplateBinding BorderThickness}"
                 BorderBrush="{DynamicResource MainBorderBrush}" />
         <Border x:Name="PART_TextBoxOverlayBorder"
                 BorderThickness="{TemplateBinding BorderThickness}"
                 BorderBrush="Transparent" />
         <Border Opacity="0.0"
                 x:Name="PART_TextBoxGlowBorder"
                 BorderBrush="{DynamicResource TextBoxHighlightBrush}"
                 BorderThickness="{TemplateBinding BorderThickness}">
            <Border.Effect>
               <BlurEffect Radius="5" />
            </Border.Effect>
         </Border>
      </Grid>
      <ControlTemplate.Triggers>
         <Trigger Property="IsEnabled"
                  Value="False">
            <Setter Property="Foreground"
                    Value="{DynamicResource DisabledForegroundBrush}" />
         </Trigger>
         <EventTrigger RoutedEvent="GotFocus">
            <EventTrigger.Actions>
               <BeginStoryboard>
                  <Storyboard>
                     <DoubleAnimation Storyboard.TargetProperty="(TextBlock.Opacity)"
                                      To="1.0"
                                      Duration="0:0:0.5" />
                  </Storyboard>
               </BeginStoryboard>
            </EventTrigger.Actions>
         </EventTrigger>
      </ControlTemplate.Triggers>
   </ControlTemplate>

   <Style TargetType="TextBox">
      <Setter Property="FontFamily"
              Value="Segoe UI" />
      <Setter Property="FontSize"
              Value="14" />
      <Setter Property="Template"
              Value="{StaticResource TextBoxControlTemplate}"/>
   </Style>

   <Style TargetType="{x:Type controls:CommandTextBox}">
      <Setter Property="FontFamily"
              Value="Segoe UI" />
      <Setter Property="FontSize"
              Value="14" />
      <Setter Property="Template"
              Value="{StaticResource TextBoxControlTemplate}" />
   </Style>

</ResourceDictionary>